package com.xbao.controller;

import com.xbao.core.http.CommRequest;
import com.xbao.core.http.CommResult;
import com.xbao.model.Rule;
import com.xbao.model.UserRole;
import com.xbao.model.req.EmpReq;
import com.xbao.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/9/4.
 */
@Api(value = "/role", tags = "role")
@RequestMapping(value = "role")
@Controller
@EnableAutoConfiguration
public class RoleController extends BaseController {
    @Resource
    private RoleService roleService;

    @ApiOperation(value = "getMyRoles", notes = "getMyRoles")
    @RequestMapping(value = "/getMyRoles", method = RequestMethod.POST)
    @ResponseBody
    public CommResult getMyRoles(@RequestBody CommRequest<EmpReq> commRequest) {
        List<Rule> rules = roleService.getMyRoles(commRequest.getData());
        return new CommResult<List<Rule>>(rules);


    }

    @RequestMapping(value = "/removeUserRole")
    @ResponseBody
    public void removeUserRole(CommRequest<UserRole> userRole) {
        roleService.removeUserRoles(userRole.getData().uid);

    }

    @RequestMapping(value = "/listUserRole")
    @ResponseBody
    public void  listUserRole(CommRequest<UserRole> userRoleCommonRequest) {
     roleService.queryRolesOfUser(userRoleCommonRequest.getData().uid);

    }

    @RequestMapping(value = "/listUserRules")
    @ResponseBody
    public CommResult<List<Rule>> listUserRules(CommRequest<UserRole> userRoleCommonRequest) {
      List<Rule> rules=  roleService.queryRulesOfUser(userRoleCommonRequest.getData().uid);
        return new CommResult<List<Rule>>(rules);

    }


}
